home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap02 / howto01 / ufmgr1.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-03-01  |  11.3 KB  |  334 lines

  1. unit Ufmgr1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl,
  8.    drwsutl1, drwsutl2;
  9.  
  10. type
  11.   TCCFileMgrForm = class(TForm)
  12.     Panel1: TPanel;
  13.     Panel2: TPanel;
  14.     BitBtn1: TBitBtn;
  15.     Panel3: TPanel;
  16.     Label1: TLabel;
  17.     BitBtn2: TBitBtn;
  18.     BitBtn3: TBitBtn;
  19.     BitBtn4: TBitBtn;
  20.     BitBtn5: TBitBtn;
  21.     BitBtn6: TBitBtn;
  22.     BitBtn7: TBitBtn;
  23.     OpenDialog1: TOpenDialog;
  24.     BitBtn8: TBitBtn;
  25.     BitBtn9: TBitBtn;
  26.     OpenDialog2: TOpenDialog;
  27.     procedure FormResize(Sender: TObject);
  28.     procedure FormCreate(Sender: TObject);
  29.     procedure BitBtn7Click(Sender: TObject);
  30.     procedure BitBtn1Click(Sender: TObject);
  31.     procedure BitBtn2Click(Sender: TObject);
  32.     procedure BitBtn3Click(Sender: TObject);
  33.     procedure BitBtn4Click(Sender: TObject);
  34.     procedure BitBtn5Click(Sender: TObject);
  35.     procedure FormPaint(Sender: TObject);
  36.   private
  37.     { Private declarations }
  38.   public
  39.     { Public declarations }
  40.     ScrollBox1 : TFileIconPanelScrollbox;
  41.     CurrentView        : Integer;  { This holds the current view setting      }
  42.   end;
  43. var
  44.   CCFileMgrForm      : TCCFileMgrForm;
  45.  
  46. implementation
  47.  
  48. {$R *.DFM}
  49.  
  50. uses DDDFUnit;  { Include custom directory selection form }
  51.  
  52. { Set up the resize to replace the icon buttons }
  53. procedure TCCFileMgrForm.FormResize(Sender: TObject);
  54. begin
  55.   { Send in the panel and global buttons list }
  56.   SpacePanelButtons( Panel2 );
  57. end;
  58.  
  59. { Delphi wrote this; use it to set everything up }
  60. procedure TCCFileMgrForm.FormCreate(Sender: TObject);
  61. var CurrentPath : String;
  62. begin
  63.   { Create the scrollbox }
  64.   ScrollBox1 := TFileIconPanelScrollBox.Create( Panel1 );
  65.   ScrollBox1.Parent := Panel1;
  66.   ScrollBox1.align := alClient;
  67.   ScrollBox1.Left := 0;
  68.   ScrollBox1.Top := 0;
  69.   ScrollBox1.Width := Panel1.Width - 32;
  70.   ScrollBox1.Height := Panel1.Height - 32;
  71.   ScrollBox1.IconsNeedRefreshing := false;
  72.   ScrollBox1.TheStoredHandle := Self.Handle;
  73.   { Get the current directory with 0 parameter }
  74.   GetDir( 0 , CurrentPath );
  75.   { Set the display caption }
  76.   Label1.Caption := CurrentPath;
  77.   { Add a trailing \ if not root }
  78.   CurrentPath := ScrollBox1.TheFWB.ForceTrailingBackSlash( CurrentPath );
  79.   { Get the icons display using scrollbox1 }
  80.   ScrollBox1.GetIconsForEntireDirectory( CurrentPath );
  81.   { Set the Icon View as default }
  82.   CurrentView := 1;
  83. end;
  84.  
  85. { Delphi wrote this; use it to close the application }
  86. procedure TCCFileMgrForm.BitBtn7Click(Sender: TObject);
  87. begin
  88.   Close;
  89. end;
  90.  
  91. { Delphi wrote this use it to perform a copy on all selected files }
  92. procedure TCCFileMgrForm.BitBtn1Click(Sender: TObject);
  93. var ThePosition  : Integer;       { Loop counter   }
  94.     CurrentName ,                 { Holds work name}
  95.     TheOldString : String;        { Holds Dir      }
  96.     finished     : Boolean;       { Loop control   }
  97.     WorkingDir   : String;        { Holds mod wd   }
  98.     TargetDir    : String;        { target of op   }
  99.     TheResult    : Integer;       { Modal res hold }
  100. begin
  101.   { Get current directory and save it for later }
  102.   GetDir( 0 , TheOldString );
  103.   { Check for need to add trailing \ }
  104.   WorkingDir := TheOldString;
  105.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDir );
  106.   { Display the Windows-based directory input form }
  107.   TheResult := DestDDForm.ShowModal;
  108.   { If not cancelled do the copy }
  109.   if TheResult = mrOK then
  110.   begin
  111.     { Get the target directory with \ OK }
  112.     TargetDir := DestDDForm.GetTargetDirectory;
  113.     { Show the hourglass to indicate waiting }
  114.     Screen.Cursor := crHourGlass;
  115.     { Setup to get all selections }
  116.     ThePosition := 1;
  117.     finished := false;
  118.     while not finished do
  119.     begin
  120.       { Call generic file getting routine based on current view}
  121.       case CurrentView of
  122.         1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  123.              ThePosition );
  124.       end;
  125.       { If returns blank string out of selections so exit }
  126.       if CurrentName = '' then finished := true else
  127.       begin
  128.         { If a directory signal error }
  129.         if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  130.         begin
  131.           MessageDlg( ' Cannot Copy Directory ' + CurrentName , mtConfirmation ,
  132.            mbYesNoCancel , 0 ); 
  133.         end
  134.         else
  135.         begin
  136.           Scrollbox1.TheFWB.CopyTheFile( CurrentName , TargetDir );
  137.         end;
  138.       end;
  139.     end;
  140.     { Reset to normal cursor }
  141.     Screen.Cursor := crDefault;
  142.   end;
  143.   { Reset to the original directory }
  144.   ChDir( TheOldString );
  145. end;
  146.  
  147. { Delphi wrote this, use it to move files which are selected }
  148. procedure TCCFileMgrForm.BitBtn2Click(Sender: TObject);
  149. var ThePosition  : Integer;       { Loop counter   }
  150.     CurrentName ,                 { Holds work name}
  151.     TheOldString : String;        { Holds Dir      }
  152.     finished     : Boolean;       { Loop control   }
  153.     WorkingDir   : String;        { Holds mod wd   }
  154.     TargetDir    : String;        { target of op   }
  155.     TheResult    : Integer;       { Modal res hold }
  156. begin
  157.   { Get current directory and save it for later }
  158.   GetDir( 0 , TheOldString );
  159.   { Check for need to add trailing \ }
  160.   WorkingDir := TheOldString;
  161.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  162.   { Display the Windows-based directory input form }
  163.   TheResult := DestDDForm.ShowModal;
  164.   { If not cancelled do the copy }
  165.   if TheResult = mrOK then
  166.   begin
  167.     { Get the target directory with \ OK }
  168.     TargetDir := DestDDForm.GetTargetDirectory;
  169.     { Show the hourglass to indicate waiting }
  170.     Screen.Cursor := crHourGlass;
  171.     { Set up to get all current selections }
  172.     ThePosition := 1;
  173.     finished := false;
  174.     while not finished do
  175.     begin
  176.       { Call generic file getting routine based on current view}
  177.       case CurrentView of
  178.         1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  179.              ThePosition );
  180.       end;
  181.       { If returns blank string then out of selections }
  182.       if CurrentName = '' then finished := true else
  183.       begin
  184.         { If a directory signal error }
  185.         if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  186.         begin
  187.           MessageDlg( 'Cannot Move Directory ' + CurrentName , mtConfirmation ,
  188.            mbYesNoCancel , 0 );
  189.         end
  190.         else
  191.         begin
  192.           Scrollbox1.TheFWB.MoveTheFile( CurrentName , TargetDir );
  193.         end;
  194.       end;
  195.       { Reset to normal cursor }
  196.       Screen.Cursor := crDefault;
  197.     end;
  198.   end;
  199.   { Reset to the original directory }
  200.   ChDir( TheOldString );
  201.   ScrollBox1.Update;
  202. end;
  203.  
  204. { Delphi wrote this, use it to delete files which are selected }
  205. procedure TCCFileMgrForm.BitBtn3Click(Sender: TObject);
  206. var ThePosition  : Integer;       { Loop counter   }
  207.     CurrentName ,                 { Holds work name}
  208.     TheOldString : String;        { Holds Dir      }
  209.     finished     : Boolean;       { Loop control   }
  210.     WorkingDir   : String;        { Holds mod wd   }
  211. begin
  212.   { Get current directory and save it for later }
  213.   GetDir( 0 , TheOldString );
  214.   { Check for need to add trailing \ }
  215.   WorkingDir := TheOldString;
  216.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  217.   { Set up to do loop for selected files }
  218.   ThePosition := 1;
  219.   finished := false;
  220.   while not finished do
  221.   begin
  222.     { Call generic file getting routine based on current view}
  223.     case CurrentView of
  224.       1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  225.            ThePosition );
  226.     end;
  227.     { if returns blank string out of selections }
  228.     if CurrentName = '' then finished := true else
  229.     begin
  230.       { If its a directory signal error }
  231.       if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  232.       begin
  233.         MessageDlg( 'Cannot Delete Directory ' + CurrentName , mtConfirmation,
  234.          mbYesNoCancel , 0 );
  235.       end
  236.       else
  237.       begin
  238.         { Otherwise get confirmation message and if OKed delete file }
  239.         if MessageDlg( 'Delete file ' + CurrentName + '?', mtConfirmation ,
  240.          mbYesNoCancel , 0 ) = mrYes then
  241.         begin
  242.           ScrollBox1.TheFWB.DeleteTheFile( Currentname );
  243.         end;
  244.       end;
  245.     end;
  246.   end;
  247.   ScrollBox1.Update;
  248. end;
  249.  
  250. { Delphi wrote this; use it to rename selected files }
  251. procedure TCCFileMgrForm.BitBtn4Click(Sender: TObject);
  252. var ThePosition  : Integer;       { Loop counter   }
  253.     CurrentName ,                 { Holds work name}
  254.     TheOldString : String;        { Holds Dir      }
  255.     finished     : Boolean;       { Loop control   }
  256.     WorkingDir   : String;        { Holds mod wd   }
  257. begin
  258.   { Get current directory for later }
  259.   GetDir( 0 , TheOldString );
  260.   { Check for need to add trailing \ }
  261.   WorkingDir := TheOldString;
  262.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  263.   { Set up to do loop for selected files }
  264.   ThePosition := 1;
  265.   finished := false;
  266.   while not finished do
  267.   begin
  268.     { Call generic file getting routine based on current view}
  269.     case CurrentView of
  270.       1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  271.            ThePosition );
  272.     end;
  273.     { If returns blank string then out of selections }
  274.     if CurrentName = '' then finished := true else
  275.     begin
  276.       { Otherwise set up the opendialog with filename and caption }
  277.       OpenDialog1.Filename := ExtractFilename( CurrentName );
  278.       { Use this to prevent error from changing directories }
  279.       OpenDialog1.Options := [ofNoChangeDir];
  280.       OpenDialog1.Title := 'Rename File';
  281.       { If not cancelled then do rename or signal error }
  282.       if OpenDialog1.Execute then
  283.       begin
  284.         ScrollBox1.TheFWB.RenameTheFile( CurrentName , OpenDialog1.Filename );
  285.       end;
  286.     end;
  287.   end;
  288.   ScrollBox1.Update;
  289. end;
  290.  
  291. { Delphi wrote this; use it to make a new directory under current one }
  292. procedure TCCFileMgrForm.BitBtn5Click(Sender: TObject);
  293. begin
  294.   { Set up the dialog to get the new directory name }
  295.   OpenDialog2.FileName := '*.*';
  296.   OpenDialog2.Title := 'Enter Directory Name';
  297.   if OpenDialog1.Execute then
  298.   begin
  299.     { If not cancelled make new directory }
  300.     Scrollbox1.TheFWB.CreateNewDirectory( OpenDialog1.Filename );
  301.   end;
  302.   ScrollBox1.Update;
  303. end;
  304.  
  305. { Delphi wrote this; use it to handle refreshing the scrollbox }
  306. procedure TCCFileMgrForm.FormPaint(Sender: TObject);
  307. var CurrentDirectory : String; { Get current dir }
  308. begin
  309.   { If updated, do refresh }
  310.   if ScrollBox1.IconsNeedRefreshing then
  311.   begin
  312.     Scrollbox1.Free;
  313.     ScrollBox1 := TFileIconPanelScrollBox.Create( Panel1 );
  314.     ScrollBox1.Parent := Panel1;
  315.     ScrollBox1.align := alClient;
  316.     ScrollBox1.Left := 0;
  317.     ScrollBox1.Top := 0;
  318.     ScrollBox1.Width := Panel1.Width - 32;
  319.     ScrollBox1.Height := Panel1.Height - 32;
  320.     ScrollBox1.IconsNeedRefreshing := false;
  321.     ScrollBox1.TheStoredHandle := Self.Handle;
  322.     GetDir( 0 , CurrentDirectory );
  323.     { Force trailing backslash }
  324.     CurrentDirectory := ScrollBox1.TheFWB.ForceTrailingBackSlash(
  325.      CurrentDirectory );
  326.     { Set the label to the new directory }
  327.     Label1.Caption := UpperCase( CurrentDirectory );
  328.     { Do the update }
  329.     ScrollBox1.GetIconsForEntireDirectory( CurrentDirectory );
  330.   end;
  331. end;
  332.  
  333. end.
  334.